package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    //按照时间和类型统计(今日注册或登陆)
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{time} AND TYPE = #{type}")
    Long countByTimeAndType(@Param("time")String time ,@Param("type") String type);

    //按照时间统计(今日活跃)
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{time}")
    Long countByTime(String time);

    // 次日留存(昨日注册,今日登陆)
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{yesterdayTime} AND TYPE = '0102' AND user_id IN (SELECT DISTINCT user_id FROM tb_log WHERE log_time = #{todayTime})")
    Long keep(@Param("yesterdayTime") String yesterdayTime,@Param("todayTime") String todayTime);
}